package com.sunny.ynhz.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.TimeBean;
import com.sunny.ynhz.utils.DensityUtil;
import com.sunny.ynhz.utils.ScreenUtils;

import java.util.List;

/**
 * Created by huhuan123 on 2018/8/7.
 *
 * @describe TODO
 */

public class TimeSelectAdapter extends BaseQuickAdapter<TimeBean, BaseViewHolder> {

    private float screenWith;
    private Context context;

    public TimeSelectAdapter(@Nullable List<TimeBean> data, Context context, int visibleCount) {
        super(R.layout.item_time, data);
        this.context = context;
        screenWith = (ScreenUtils.getScreenWith(context) - DensityUtil.dip2px(context, 40) * 2) / visibleCount;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void convert(BaseViewHolder helper, TimeBean item) {
//        RecyclerView.LayoutParams layoutParams=new RecyclerView.LayoutParams((int)screenWith, RecyclerView.LayoutParams.WRAP_CONTENT);
//        helper.itemView.setLayoutParams(layoutParams);
        View itemView = helper.itemView;
        ViewGroup.LayoutParams layoutParams = itemView.getLayoutParams();
        layoutParams.width = (int) screenWith;
        itemView.requestLayout();
        helper.setText(R.id.tv_time, item.getTime());

        if (!item.isExit()) {
            helper.itemView.setClickable(false);
            helper.setTextColor(R.id.tv_time, Color.parseColor("#bdbdbd"));
            helper.getView(R.id.tv_time).setBackground(null);
        } else {
            helper.itemView.setClickable(true);
            if (item.isCheck) {
                helper.setTextColor(R.id.tv_time, Color.WHITE);
                helper.getView(R.id.tv_time).setBackground(context.getDrawable(R.drawable.bg_blue1));
            } else {
                helper.setTextColor(R.id.tv_time, Color.parseColor("#666666"));
                helper.getView(R.id.tv_time).setBackground(null);
            }
        }


    }
}
